package com.base.common.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.operamasks.faces.annotation.Convert;
import org.operamasks.faces.annotation.DefineConverter;
import org.operamasks.faces.annotation.Format;

import com.base.commonKey.CommonkeyReplace;

/**
 * 用于将keyId转换成keyValue的转换类
 * 
 * @author chengang
 * 
 */

@DefineConverter(id = "commonKeyFormatter")
public class CommonKeyConverter implements Converter {
	private final static Log logger = LogFactory
			.getLog(CommonKeyConverter.class);

	@Format
	public String format(Object value) {
		if (value == null || "".equals(value.toString()))
			return "";
		String userId = value.toString();
		return CommonkeyReplace.replaceCommonKey(userId);
	}

	@Convert
	public Object convert(String value) {
		return null;
	}

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		return null;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		if (value == null || "".equals(value.toString()))
			return "";
		String userId = value.toString();
		return CommonkeyReplace.replaceCommonKey(userId);
	}

}
